import Vue from 'vue';
import Vuex from 'vuex';
import plugin from './plugins/syncStorage';

// 导入所有状态模块
const allComponents = require.context('./modules/', false, /^.*\.js$/);
const res_components = {};
allComponents.keys().forEach(filename => {
  const comp = allComponents(filename);
  const key = filename.replace('./', '').replace('.js', '');
  res_components[key] = (comp.default);
});

Vue.use(Vuex);

const state = {
  isCollapse: true
};

const getters = {
  getCollapse: (state) => {
    return state.isCollapse;
  }
};

const mutations = {
  setCollapse: (state, payload) => {
    state.isCollapse = payload;
  }
};

const actions = {
};

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  plugins:[
    plugin
  ],
  modules: {
    ...res_components
  }
});
